package com.coder.bike.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.coder.bike.entity.RentalType;
import com.coder.bike.service.IRentalTypeService;
import com.coder.bike.utils.Result;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 共享单车租赁类型表 前端控制器
 * </p>
 *
 * @author 沈诩宸
 * @since 2025-04-22
 */
@RestController
@RequestMapping("/rental/rentalType")
public class RentalTypeController {

        @Resource
        private IRentalTypeService rentalTypeService;
        @GetMapping
        public Result listAll(){
            return Result.success(rentalTypeService.list());
        }
        @PostMapping("{start}/{size}")
        public Result search(@PathVariable int start, @PathVariable int size,
                             @RequestBody RentalType rentalType){
            Page<RentalType> page=new Page<>(start,size);
            return
                    Result.success(rentalTypeService.searchByPage(page,rentalType));
        }
        @PostMapping
        public Result save(@RequestBody RentalType rentalType){
            return rentalTypeService.save(rentalType)?
                    Result.success():Result.fail();
        }
        @PutMapping
        public Result update(@RequestBody RentalType rentalType){
            return rentalTypeService.updateById(rentalType)?
                    Result.success():Result.fail();
        }
        @DeleteMapping("/{ids}")
        public Result delete(@PathVariable String ids){
            return rentalTypeService.delete(ids)?Result.success():Result.fail();
        }

}
